package org.springblade.resource.feign;

import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import org.springblade.core.oss.model.BladeFile;
import org.springblade.core.tenant.annotation.NonDS;
import org.springblade.core.tool.api.R;
import org.springblade.resource.builder.oss.OssBuilder;
import org.springblade.resource.oss.BladeFileWithType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@NonDS
@RestController
@AllArgsConstructor
public class OssClient implements IOssClient{

	/**
	 * 对象存储构建类
	 */
	private final OssBuilder ossBuilder;

	@Override
	@SneakyThrows
	@PostMapping(PUT_FILE)
	public R<BladeFileWithType> putFile(@RequestParam MultipartFile file) {
		BladeFile bladeFile = ossBuilder.template().putFile(file.getOriginalFilename(), file.getInputStream());
		return R.data(new BladeFileWithType(bladeFile, file.getInputStream()));
	}
}
